package com.xingongchang.baolebei.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.xingongchang.baolebei.ImageDisplay;
import com.xingongchang.baolebei.R;
import com.xingongchang.baolebei.protocol.Goos_item;

public class GoosItemAdapter extends BaseAdapter {
	private ImageLoader imageLoader = ImageLoader.getInstance();
		private LayoutInflater inflater;
		private ArrayList<Goos_item> goods = new ArrayList<Goos_item>();
        Context mcontext;
		public GoosItemAdapter(Context context,
				ArrayList<Goos_item> recommendGoods) {
			this.inflater = LayoutInflater.from(context);
			this.goods = recommendGoods;
			this.mcontext=context;
			ImageDisplay.show(mcontext);
		}

		@Override
		public int getCount() {
			return goods.size();
		}

		@Override
		public Object getItem(int position) {
			return goods.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = this.inflater.inflate(R.layout.gooditem, null);
				holder.goods_photo = (ImageView) convertView
						.findViewById(R.id.gooditem_photo);
				holder.goods_name = (TextView) convertView
						.findViewById(R.id.good_desc);
				holder.goods_price = (TextView) convertView
						.findViewById(R.id.shop_price);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			Goos_item good = goods.get(position);
			ImageDisplay.show(mcontext,good.goods_thumb, holder.goods_photo);
			holder.goods_name.setText(good.goods_name);
			holder.goods_price.setText(good.shop_price);
			return convertView;
		}

		private class ViewHolder {
			ImageView goods_photo;
			TextView goods_name;
			TextView goods_price;
		}
}
